package cn.myjerry.memento;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Caretaker {
	
	private EmpMemento empMemento;
	private Map<String, EmpMemento> map = new HashMap<>();

	public EmpMemento getEmpMemento() {
		return empMemento;
	}

	public void setEmpMemento(EmpMemento empMemento) {
		this.empMemento = empMemento;
	}
	
	public void add(EmpMemento empMemento) {
		this.map.put(new Date().toString(), empMemento);
	}
	
	public List<String> getKeys() {
		List<String> list = new ArrayList<>();
		Iterator<Entry<String, EmpMemento>> it = map.entrySet().iterator();
		while(it.hasNext()) {
			if(it.next().getKey().isEmpty()) {
				list.add(it.next().getKey());
			}
		}
		return list;
	}
	
	public EmpMemento getMemento(String str) {
		return map.get(str);
	}
	
}
